﻿#region <!-- Using Directives -->

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

using WordSharpDev.Utils;

#endregion

namespace WordSharpDev.Extensions
{
	internal static class ErrExtensions
	{
		#region <!-- ToXmlNode -->

		public static XmlNode ToXmlNode(this Exception p_This)
		{
			if (p_This == null) return null;

			if (p_This is ErrException) return ((ErrException)p_This).ToXmlNode();

			var l_Node = "<Exception />".AsXmlNode();

			var l_Params = String.Format("{0}\r\n{1}", "Type", p_This.GetType().Name);

			l_Node.GetNewChild("Params").AppendData(l_Params);

			l_Node.GetNewChild("Message").AppendData(p_This.Message);

			if (p_This.InnerException != null)
			{
				l_Node.GetNewChild("Exception").InnerXml = p_This.InnerException.ToXmlNode().InnerXml;
			}

			return l_Node;
		}

		#endregion
	}
}